public class Test {
    //switch语句中的break不可省略，如果不省略，便会继续往下读取
    //switch不能做switch参数的数据类型有double,float,long,boolean
    public static void main4(String[] args) {
        int a = 10;
        switch(a){
            case 1:
                System.out.println("1");
                break;
            case 2:
                System.out.println("2");
                break;
            case 3:
                System.out.println("3");
                break;
            default:
                System.out.println("4");
                break;
        }
    }
    //计算1~100的和
    public static void main2(String[] args) {
        int n = 1;
        int ret = 0;
        while(n <= 100){
           ret += n;
           n++;
        }
        System.out.println(ret);
    }
   //打印1~10的数字
    public static void main1(String[] args) {
        int num = 1;
        while(num<=10){
            System.out.println(num);
            num++;
        }
    }

    public static void main3(String[] args) {
        //计算5的阶乘
        int num = 1;
        int ret = 1;
        while(num <= 5){
            ret *= num;
            num++;
        }
        System.out.println("ret=" + ret);
    }

    //计算从1到n的和
    public static void main8(String[] args) {
        int num = 1;
        int sum = 0;
        while(num <= 5){
            int n = 1;
            int ret = 1;
            while(n <= num){
                ret *=n;
                n++;
            }
            sum += ret;
            num++;
        }
        System.out.println(sum);
    }


    public static void main5(String[] args) {
        int a = 9;
        System.out.println(a);
        //练习：判断一个数字是否为奇数或偶数
        int a1 = 10;
        if (a1 % 2 != 0) {
            System.out.println("奇数");
        } else {
            System.out.println("偶数");
        }
    }

    public static void main6(String[] args) {//练习2
        int num=0;
        if(num>0){
            System.out.println("则这个数为正整数");
        }else if(num<0){
            System.out.println("则这个数为负整数");
        }else{
            System.out.println("那么这个数则为0");
        }
    }
    public static void main7(String[] args) {
        int year = 2020;
        if (year % 100 == 0) {
            if (year % 400 == 0) {
                System.out.println("则这个年为闰年");
            } else {
                System.out.println("则该年不是闰年");
            }
        }else{
            if(year%4==0){
                System.out.println("则该年为闰年");
            }else{
                System.out.println("则该年不为闰年");
            }
        }
    }

    //break会提前结束循环，跳出循环
    //continue跳过本次循环，进入到下一次循环；也就是在循环中continue后面的内容不会再被执行

}


